﻿using HZY.Framework.DependencyInjection;
using Long.BLL;
using Long.Helper;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Long.SpraySCADA
{
    public partial class PageChartManage : UIPage, ISingletonSelfDependency
    {
        private readonly DataManager _dataManager;
        public PageChartManage(DataManager dataManager)
        {
            InitializeComponent();
            this._dataManager = dataManager;

            this.dtp_Start.Value = DateTime.Now.AddHours(-3);
            this.dtp_End.Value = DateTime.Now;

            UILineOption option = new UILineOption()
            {
                ToolTip = { Visible = true },//鼠标悬停显示提示信息
                Title = new UITitle { Text = "" },
                Legend = new UILegend
                {
                    Orient = UIOrient.Horizontal, //设置图例的方向为水平
                    Top = UITopAlignment.Top, //设置图例的位置为顶侧
                    Left = UILeftAlignment.Left, //设置图例的位置为左侧
                },
                XAxisType = UIAxisType.DateTime,//设置X轴的类型为时间
                XAxis = { Name = "时间", AxisLabel = { DateTimeFormat = "HH:mm:ss" } },
                YAxis = {Name = "数值", AxisLabel = { DecimalPlaces = 2}
                }
            };

            string[] legendData =
            {
                "脱脂喷淋泵压力值",
                "脱脂pH值",
               // "陶化pH值",
                "粗洗喷淋泵压力值",
                "陶化喷淋泵压力值",
                "粗洗喷淋泵压力值",
                "水分炉测量温度",
                "固化炉测量温度"
            };

            foreach (var data in legendData)
            {
                option.Legend.Data.Add(data);
                AddSide(option, data);
            }

            lc_Chart.SetOption(option);
        }
        private void AddSide(UILineOption option,string sericesName)
        {
            UILineSeries series = option.AddSeries(new UILineSeries(sericesName));
            series.Symbol = UILinePointSymbol.Circle;
            series.SymbolSize = 4;
            series.SymbolLineWidth=2;
            series.Smooth = true;
        }

        private async void btn_QueryData_Click(object sender, EventArgs e)
        {
            DateTime start = this.dtp_Start.Value;
            DateTime end = this.dtp_End.Value;
            if (start >= end)
            {
                MessageBox.Show("开始时间不能大于结束时间！");
                return;
            }
            DataQueryDto dto = new DataQueryDto()
            {
                StartTime = start,
                EndTime = end
            };
            BaseResult<DataQuaeryResulyDto> res = await this._dataManager.GetDataListByTimeAsyncManager(dto);
            if(res.ResultStatus == SystemEnums.ResultStatus.Success)
            {
                for (int i = 0; i < res.Data.Count; i++)
                {
                    if (i > 30)
                    {
                        break;
                    }
                    var dt = res.Data[i].InsertTime;
                    DataQuaeryResulyDto dataRes = res.Data[i];

                    lc_Chart.Option.AddData("脱脂喷淋泵压力值",dt, double.Parse(dataRes.脱脂喷淋泵压力值));
                    lc_Chart.Option.AddData("脱脂pH值", dt, double.Parse(dataRes.脱脂pH值));
                   // lc_Chart.Option.AddData("陶化pH值", dt, double.Parse(dataRes.陶化pH值));
                    lc_Chart.Option.AddData("粗洗喷淋泵压力值", dt, double.Parse(dataRes.粗洗喷淋泵压力值));
                    lc_Chart.Option.AddData("陶化喷淋泵压力值", dt, double.Parse(dataRes.陶化喷淋泵压力值));
                    lc_Chart.Option.AddData("粗洗喷淋泵压力值", dt, double.Parse(dataRes.粗洗喷淋泵压力值));
                    lc_Chart.Option.AddData("水分炉测量温度", dt, double.Parse(dataRes.水分炉测量温度));
                    lc_Chart.Option.AddData("固化炉测量温度", dt, double.Parse(dataRes.固化炉测量温度));
                }
            }
          
            lc_Chart.Refresh();
        }
        #region 窗体切换卡顿
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams paras = base.CreateParams;
                paras.ExStyle |= 0x02000000;
                return paras;
            }
        }
        #endregion
    }
}
